#{extends 'main.html' /} 
#{set title:'View Sprint BackLog' /}
<script>
	jQuery(function($){
		$(".SBtiptip").tipTip({
			fadeIn:30,
			fadeOut:30
		});
		
		$('.editAssignee').editable({
                onSubmit: editAssignee
            });
			$('.edit').editable({
                onSubmit: effort
            });
        });
	var rowVisible = true;
        function toggleDisplay(tbl, name){
            var tblRows = tbl.rows;
            for (i = 0; i < tblRows.length; i++) {
                if (tblRows[i].className != "StroyRow" && tblRows[i].className == name) {
                    tblRows[i].style.display = (rowVisible) ? "none" : "";
                }
            }
            rowVisible = !rowVisible;
        }
</script>

<link rel="stylesheet" href="/public/stylesheets/tableStyle.css" />
<h2><a style ="color:#400040;" href=" @{Projects.showProject(pro.getEntityId())}"> ${sp.project.name} </a> > <a style ="color:#400040;" href="@{Events.showSprint(sp.getEntityId())}">${sp.name}</a> > Sprint Backlog</h2><hr/>
		#{list  items:pro.components,  as:'projectComponentList'}
		#{if projectComponentList.name!="Default component"}
		<a href="@{SprintBacklog.viewComponentS(projectComponentList.getEntityId(),sp.project.getEntityId(),sp.getEntityId())}">view ${projectComponentList.name} Sprint Backlog</a><br/>
		#{/if}
		#{/list}
<div  style="overflow:scroll; height:500px; width=900px">
<table id="SPRNTBcklog" border=4 align="center" cellspacing=0>
	<thead>
    <tr>
        <th>
            Sprint Name: 
        </th>
        <th>
        	<a style ="color:#400040;" href="@{Events.showSprint(sp.getEntityId())}">${sp.name}</a>
        </th>
        <th align="center">
            Initial
            <br>
            </br>
            Estimated
            <br>
            </br>
            points 
            <br>
            </th>
			<th colspan="${sd}">
				Effort Points Remaining
			</th>
            
        </tr>
        <br>
        <tr>
        	<th></th>
            <th align="center">
                WHO? 
            </th>
            <th align="center">
                Day 
                <br>
                </br>
                0 
            </th>
            #{list items:forSprintduration, as:'Day'}
            <th>
                Day
                <br>
                </br>
                ${Day}
            </th>
            #{/list}
        </tr>
        <tr>
            <th style="border:none">
            </th>
            <th style="border:none">
            </th>
            <th>
            </th>
                #{list items:forSprintduration, as:'Day'}
                <th>
                </th>
                #{/list}
            </tr>
			</thead>
			<tbody>
           		 <tr>
           		 	<!--Stories-->
				<tr>
					#{list items:pro.components, as:'componentsEv'}
					#{if componentsEv.name!="Default component"}
            		<th class="th2" colspan="2" onclick="toggleDisplay(document.getElementById('SPRNTBcklog'),'${stories}')">
            			<h3 class="Tablecomponent"> Component ${componentsEv.name} </h3>
            		</th>
					 <td align="left" style="border:none">
                		<img id="ex_col" class="SBtiptip" title="click on it to hide/show" onclick="toggleDisplay(document.getElementById('SPRNTBcklog'),'${componentsEv.name}')" src="/public/images/plusmin.gif"/>
				</td>
					
            	</tr>
     			#{if allPs!=null} 
                #{list items:allPs, as:'stories'}
				#{if componentsEv.id==stories.component.id}
                <tr class="${componentsEv.name}" >
                    <th class="th SBtiptip" colspan="3" onclick="toggleDisplay(document.getElementById('SPRNTBcklog'),'${stories.story}')" title="click on it to hide/show">
                    	${stories.story}
                    </th>
					
                    #{list items:stories.tasks,as:'Tasklist'}
					#{if Tasklist.initialEffortEstimation != 0.0}
                    <tr class="${stories.story}">
                        <td align="right">
                        	#{if Tasklist.type.type=="Impediment"}
								<img class="SBtiptip" src="/public/images/obstacles.jpg" title="This is an impediment task" align="center"/>
							#{/if}
                            ${Tasklist.description}
							
                        </td>
						#{if controllers.Events.sprintInProgress(sp.id)}
						 #{if controllers.Security.checkPermission(' edit the assignee of a task ',pro)== true}
						<td id="${Tasklist.id}" class="editAssignee SBtiptip" title="You Can edit the assignee of the task"> #{if controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()) != null} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).firstName} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).lastName} #{/if}</td>
						#{/if}
						#{else}
						<td> #{if controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()) != null} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).firstName} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).lastName} #{/if}</td>
						#{/else}
						#{/if}
						#{else}
						<td> #{if controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()) != null} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).firstName} ${controllers.Tasks.getTaskAssignee(Tasklist.getEntityId()).lastName} #{/if}</td>
						#{/else}
                        <td align="center">
                            ${Tasklist.initialEffortEstimation}
                        </td>
						<!--This is the days empty cell beside each task-->

						%{i=0;}%
						#{list items:controllers.SprintBacklog.getEffortsTillNow2(sp.id,Tasklist.id), as:'Effrt'}
						%{
						  i++;
						  }%
						  #{if controllers.Users.isSystemAdmin()==true}
						  <td id="${Tasklist.id}" text="${Effrt.id}" class="edit SBtiptip" title="You Can Enter Remaining Effort">#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/if}
						  #{elseif controllers.Events.sprintInProgress(sp.id)}
						  #{if controllers.SprintBacklog.assignedmem(Tasklist.id)}
						<td id="${Tasklist.id}" text="${Effrt.id}" class="edit SBtiptip" title="Enter Ur Remaining Effort">#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/if}
						#{else}
						<td >#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/else}
						#{/elseif}
						#{else}
						<td >#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/else}
						#{/list}

                    </tr>
					#{/if}
					#{/list}
					
                </tr>
					#{/if}
                	#{/list}
					#{/if}
					#{/if}
					#{/list}
					<!--End of stories-->
					<!-- tasks-->
				#{if allPTasks!=null}
				<tr>
            		<th class="th2" colspan="2" onclick="toggleDisplay(document.getElementById('SPRNTBcklog'),'TaskRows')">
            			<h3 class="Tablecomponent">Stand-Alone tasks</h3>
            		</th>
            	</tr>
				
				#{list items:allPTasks, as:'taskss'}
				#{if taskss.initialEffortEstimation != 0.0}
                <tr class="TaskRows">
              		<tr>
                        <td align="right">
                        	#{if taskss.type.type=="Impediment"}
								<img class="SBtiptip" src="/public/images/obstacles.jpg" title="This is an impediment task"/>
							#{/if}
                            ${taskss.description}
                        </td>
						 #{if controllers.Events.sprintInProgress(sp.id)}
						 #{if controllers.Security.checkPermission(' edit the assignee of a task ',pro)== true}
						<td id="${Tasklist.id}" class="editAssignee SBtiptip" title="You Can edit the assignee of the task"> #{if controllers.Tasks.getTaskAssignee(taskss.getEntityId()) != null} ${controllers.Tasks.getTaskAssignee(taskss.getEntityId()).firstName} ${controllers.Tasks.getTaskAssignee(taskss.getEntityId()).lastName} #{/if}</td>
						#{/if}
						#{else}
						<td id="${Tasklist.id}"> #{if controllers.Tasks.getTaskAssignee(taskss.getEntityId()) != null} ${controllers.Tasks.getTaskAssignee(taskss.getEntityId()).firstName} ${controllers.Tasks.getTaskAssignee(taskss.getEntityId()).lastName} #{/if}</td>
						#{/else}
						#{/if}
						#{else}
						<td> #{if controllers.Tasks.getTaskAssignee(taskss.getEntityId()) != null} ${controllers.Tasks.getTaskAssignee(taskss.getEntityId()).firstName} ${controllers.Tasks.getTaskAssignee(taskss.getEntityId()).lastName} #{/if}</td>
						#{/else}
                        <td align="center">
                            ${taskss.initialEffortEstimation}
                        </td>
						<!--This is the days empty cell beside each task-->
						
						#{list items:controllers.SprintBacklog.getEffortsTillNow2(sp.id,taskss.id), as:'Effrt'}
						#{if controllers.Users.isSystemAdmin()==true}
						<td id="${taskss.id}" text="${Effrt.getEntityId()}" class="edit SBtiptip" title="You Can Enter Remaining Effort">#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/if}
						  #{elseif controllers.Events.sprintInProgress(sp.id)}
						 #{if controllers.SprintBacklog.assignedmem(taskss.id)}
						<td id="${taskss.id}" text="${Effrt.getEntityId()}" class="edit SBtiptip" title="Enter Ur Remaining Effort">#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/if}
						#{else}
						<td >#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/else}
						#{/elseif}
						#{else}
						<td >#{if Effrt.actualEffort!=-1.0}${Effrt.actualEffort}#{/if}</td>
						#{/else}
						#{/list}
						

                         </tr>
				 	</tr>
				#{/if}	
				#{/list}
				
				
					
                #{/if}
				<!--end of tasks-->
            </tr>
			</tbody>
        </table>
	</div>
  <br></br>
  <script>
  	function editAssignee(content){	
	if(content.current == "" || content.current == null)
		window.location.reload(true);
		else{
        		$.post('@{Tasks.editTaskAssignee()}',
        	{taskId:content.id,
        	newValue:content.current,
			proId:'${projectID}'},function(){
						window.location.reload(true);});
        		}

        }
		function effort(content){
			
			if (isNaN(content.current) || content.current == "" || content.current == null||content.current>99 || content.current<0)
			showDialogHelper('Error!','Check ur input', false,'','error');
				else{
				if (content.previous == "" || content.previous == null) {
					$.post('@{SprintBacklog.addDayEditEffort()}', {
						sprintId: '${sp.id}',
						taskId: content.id,
						effort: content.current,
						dayNum: content.text
					}, function(){
						window.location.reload(true);
					});
				}
				else {
					$.post('@{SprintBacklog.editEffort()}', {
						sprintId: '${sp.id}',
						taskId: content.id,
						effort: content.current,
						dayNum: content.text,
						oldEffort: content.previous
					}, function(){
						window.location.reload(true);
					});
				}
			}

       	}
  
  </script>